package com.study.spring.queue;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.TextMessage;


@Component
public class SpringMQConsume {

    @Autowired
    JmsTemplate jmsTemplate;

    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("SpringTopicMQ.xml");

        SpringMQConsume springMQConsume = (SpringMQConsume)context.getBean("springMQConsume");

        TextMessage message = (TextMessage)springMQConsume.jmsTemplate.receive();

        try {
            System.out.println(message.getText());
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
